<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/conn.asp"-->
<!--#include file="lib/saferequest.asp"-->
<!--#include file="lib/error_write.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="stylesheet" href="lib/sheet.css" type="text/css" />
<link type="text/css" rel="stylesheet" href="lib/ui/themes/base/ui.all.css" />
<!-- jquery和ui -->
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/ui/ui.core.js"></script>
<script type="text/javascript" src="lib/ui/ui.datepicker.js"></script>
<script type="text/javascript" src="lib/ui/i18n/ui.datepicker-zh-CN.js"></script>
<script type="text/javascript">
	$(function() {
		$.datepicker.setDefaults({
			changeMonth: true,
			changeYear: true
		});
		$(".datepicker").datepicker();
		$(".contable").addClass("ct");	//载入table样式
		$("table.contable th").addClass("ch").css("background-color","silver");	//载入th样式
		$("table.contable td").addClass("ld");	//载入td样式
		$("#dd,#xx").change(function(){
			$.get("yj.asp",{didian:$("#dd").val(),xiangxing:$("#xx").val()},function(data){
				//alert(data);
				if (!data){
					$("#yj,#jsj,#rlf,#sjrlf,#glf,#ltf,#chanzhi").val(0);
					return false;
				}
				//$("#yj").val(data.yunjia);
				$("#zdyj").html(data.yunjia);

				//$("#rlf,#sjrlf").val(data.zdrlf);
				$("#rlf").val(data.zdrlf);
				//$("#glf,#ltf").val(data.zdglf);
				$("#glf").val(data.zdglf);
				$("#chanzhi").val(data.chanzhi);
			},"json");
		});
		$("#tixiang,#huanxiang").change(function(){
			var tx=hx=0;
			$.get("tx.asp",{tx:$("#tixiang").val()},function(data){
				//alert(data);
				(!data)? tx=0 : tx=data.tx;
				$("#jgf").val(tx+hx);
			},"json");
			$.get("hx.asp",{hx:$("#huanxiang").val()},function(data){
				//alert(data);
				(!data)? hx=0 : hx=data.hx;
				$("#jgf").val(tx+hx);
			},"json");
		});
		$("#xh").blur(function(){
			$("#xh_memo").load("container_coding.asp?xh="+$(this).val());
		});
		$("#thf").keypress(function(){
			if($("#tixiang").val()==""&&$("#huanxiang").val()=="") alert("请输入提箱或还箱!");
		});
		$("#jgf").blur(function(){
			if($("#thf").val()!=""&&$("#jgf").val()=="") alert("请输入进港费!");
			if($("#jsj").val()=="") jsj=0; else jsj=Number($("#jsj").val());
			if($("#jgf").val()=="") jgf=0; else jgf=Number($("#jgf").val());
			
			$("#glcbf").html(((jsj+jgf)*0.1).toFixed(2));
			
		});
		$("#djf").blur(function(){
			if($("#xx").val()!="20"&&Number($("#djf").val())<70) alert("吊机费小于70，箱型应该是20，请修改!");
			$("#xx").focus();
		});
		$("#jsj").blur(function(){
			
			if($("#jsj").val()=="") jsj=0; else jsj=Number($("#jsj").val());
			if($("#jgf").val()=="") jgf=0; else jgf=Number($("#jgf").val());
			
			$("#glcbf").html(((jsj+jgf)*0.1).toFixed(2));
		});



		var j=-1;
		function getkeycode(e){
			var keyc;
			if(window.event){
				keyc=e.keyCode;
			}else if(e.which){
				keyc=e.which;
			}
			return keyc;
		}

		function tyrover(n,mn){
			for(var i=0;i<mn;i++){
				if(i>=0&&i<mn&&i==n){
					$("#ttyr tr").eq(i).addClass("gac_b");	//添加css样式
				}else{
					$("#ttyr tr").eq(i).removeClass("gac_b");	//添加css样式
				}

			}

		}

		$("#tyr").keyup(function(e){
			var tyr=$("#tyr");
			if(getkeycode(e)==13||getkeycode(e)==38||getkeycode(e)==40){
				var	ttr=$("#ttyr tr");
				if(getkeycode(e)==13&&($("#ttyr").css("visibility")=="visible")) {
					//alert(j);
					tyr.val(ttr.eq(j).text());
					j=-1;
					$("#ttyr").css("visibility","hidden");
				}
				if(getkeycode(e)==40){
					j++;
					if(j>=ttr.length) j=0;
					tyr.val(ttr.eq(j).text());
					tyrover(j,ttr.length);
				}else	if(getkeycode(e)==38){
					j--;
					if(j==-1) j=ttr.length-1;
					tyr.val(ttr.eq(j).text());
					tyrover(j,ttr.length);
				}
				return;
			}
			$("#ttyr").css("left",tyr.offset().left).css("top",tyr.offset().top+tyr.outerHeight()-1).width(tyr.outerWidth());	//outerHeight()有margin是否选中的选项，注意！
			//$("#ttyr").css("left",(tyr.offset().left).toString()+"px").css("top",(tyr.offset().top+tyr.height()+5).toString()+"px").css("width",(tyr.width()+6).toString()+"px");	//原先的定位代码
			//		alert(tyr.offset().left);
			//e.preventDefault();
			if(tyr.val().length>0){	//输入框内容大于0就开始查询
				$.get("tyr.asp",{tyr:$(this).val()},function(data){
					if(!data.length){
						j=-1;
						$("#ttyr").css("visibility","hidden");
					}else{
						//alert(data[0].tyr);

						var ttyr="";
						for(var i=0;i<data.length;i++)	//for(var i=0;i<data.length&&i<=10;i++)最多显示10条，也可以通过数据库控制返回最多10条
						{
							ttyr+="<tr><td class='gac_c'>"+data[i].tyr+"</td></tr>";
							//alert(ttyr);
						}
						//alert(ttyr);
						$("#ttyr").html(ttyr).css("visibility","visible");
						$("#ttyr tr").mouseover(function(){	//对返回的dom进行mouseowver事件捕获
							$("#ttyr tr").eq(j).removeClass("gac_b");
							$(this).addClass("gac_b");	//添加css样式
							j=$("#ttyr tr").index($(this));
						}).mouseout(function(){	//对dom进行mouseout事件捕获
							$(this).removeClass("gac_b");	//移除css样式
						}).click(function(){
							tyr.val($(this).text());
							j=-1;
							$("#ttyr").css("visibility","hidden");
						});
						tyr.blur(function(){
							j=-1;
							setTimeout("$('#ttyr').css('visibility','hidden');", 200);	//设置延时隐藏列表的时间，以便有时间让click事件能取得数据
						});
					}
				},"json");
			}else{
				j=-1;
				$("#ttyr").css("visibility","hidden");	//输入框没有内容时隐藏提示框
			}
		}).keydown(function(e){
			if(getkeycode(e)==13) return false;
		});
	});
</script>

<!--#include file="lib/keydown.asp"-->

</head>
<%
If Not Session("MM_Reg") Then
	response.write("您没有登陆，请登陆后使用!<br>")
	response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a><br> "
	response.end
End If
if Session("MM_Flag")<4 then
	response.write("您没有添加权限！<br>")
	response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a><br> "
	response.End
end if
if Session("MM_Post")<>0 Then
	response.write("您没有此岗位操作权限！<br>")
	response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a><br> "
	response.End
end If
%>
<body>
<%
if request.form("tj")="添加" then
	sj=trim(SafeRequest("sj",0))
	rq=trim(SafeRequest("rq",0))
	if rq="" then error_write "1","没有填写[日期]"
	tyr=trim(SafeRequest("tyr",0))
	if tyr="" then error_write "2","没有填写[托运人]"
	cyr=trim(SafeRequest("cyr",0))
	if cyr="" then error_write "3","没有填写[承运人]"
	dd=trim(SafeRequest("dd",0))
	cmhc=trim(SafeRequest("cmhc",0))
	tdh=trim(SafeRequest("tdh",0))
	xx=trim(SafeRequest("xx",0))
	xh=trim(SafeRequest("xh",0))
	fh=trim(SafeRequest("fh",0))
	tx=trim(SafeRequest("tixiang",0))
	hx=trim(SafeRequest("huanxiang",0))
	djf=trim(SafeRequest("djf",0))
	if djf="" then djf=0
	glf=trim(SafeRequest("glf",0))
	if glf="" then glf=0
	ltf=trim(SafeRequest("ltf",0))
	if ltf="" then ltf=0
	rlf=trim(SafeRequest("rlf",0))
	if rlf="" then rlf=0
	sjrlf=trim(SafeRequest("sjrlf",0))
	if sjrlf="" then sjrlf=0
	xlf=trim(SafeRequest("xlf",0))
	if xlf="" then xlf=0
	thf=trim(SafeRequest("thf",0))
	if thf="" then thf=0
	If (tx="" And hx="") And thf<>0 Then error_write "4","请填写[提箱]或[还箱]"
	dcf=trim(SafeRequest("dcf",0))
	if dcf="" then dcf=0
	qtf=trim(SafeRequest("qtf",0))
	if qtf="" then qtf=0
	cbbz=trim(SafeRequest("cbbz",0))
	yj=trim(SafeRequest("yj",0))
	if yj="" then yj=0
	chanzhi=trim(SafeRequest("chanzhi",0))
	if chanzhi="" then chanzhi=0
	jsj=trim(SafeRequest("jsj",0))
	if jsj="" then jsj=0
	jgf=trim(SafeRequest("jgf",0))
	if jgf="" then jgf=0
	If thf<>0 And jgf=0 Then error_write "5","请填写[进港费]"
	bz=trim(SafeRequest("bz",0))
	lrsj=trim(SafeRequest("lrsj",0))
	baozhang=saferequest("baozhang",0)
	If baozhang="" Then
		baozhang=False
		baozhangsj="1900-1-1"
	Else
		baozhang=True
		baozhangsj=Date()
	End If
	if lrsj="" then error_write "23","没有填写[录入日期]"
	if xh<>"" or fh<>"" then
		sql="select * from yb where xh='"&xh&"' and fh='"&fh&"'"
		set chongfu=server.createobject("adodb.recordset")
		chongfu.open sql,conn,1,1
		if not chongfu.eof then	 error_write "24","箱号和封号重复，请检查！"
	end if
	sql="insert into yb(sj,rq,tyr,cyr,dd,cmhc,tdh,xx,xh,fh,tx,hx,djf,glf,ltf,rlf,sjrlf,xlf,thf,dcf,qtf,cbbz,chanzhi,yj,jsj,jgf,bz,lrsj,baozhang,baozhangsj,gxry) values('"&sj&"','"&rq&"','"&tyr&"',"&cyr&",'"&dd&"','"&cmhc&"','"&tdh&"','"&xx&"','"&xh&"','"&fh&"','"&tx&"','"&hx&"',"&djf&","&glf&","&ltf&","&rlf&","&sjrlf&","&xlf&","&thf&","&dcf&","&qtf&",'"&cbbz&"',"&chanzhi&","&yj&","&jsj&","&jgf&",'"&bz&"','"&lrsj&"',"&baozhang&",'"&baozhangsj&"','"&session("MM_Username")&"')"
	'response.write sql
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection=conn
	cmd.CommandText = sql
	cmd.Execute
	response.write("添加成功，可以继续添加下一条，察看添加的数据请返回！")
	set rs_new=server.createobject("adodb.recordset")
	sql_new="select id from yb where id=(select max(id) as Last_Id from yb)"
	rs_new.open sql_new,conn,1,1
	id=rs_new("id")
	rs_new.close
	view_url="view.asp?id="&id
	response.Redirect(view_url)
end if

%>
<form name="form1" method="post" action="#">
<table class="contable">
		<tr>
			<th colspan="4"><font size="4">基本信息</font>(录入时间:<input class="datepicker" name="lrsj" id="lrsj" size="10" value="<%=date()%>" />)
			</th>
		</tr>
  <tr>
    <th>序号</th>
    <td>&nbsp;</td>
    <th>货单日期</th>
    <td><input class="datepicker" name="rq" id="rq" value="<%=date()%>" />
</td>
  </tr>
  <tr>
    <th>托运人</th>
    <td><select id="tyr" name="tyr">
		<%
		set rs_tyr = Server.CreateObject("ADODB.Recordset")
sql="select tyr from (select tyr,count(tyr) as n from yb group by tyr) order by n desc"
rs_tyr.open sql,conn,1,1
While Not rs_tyr.eof
%>
	 <option value="<%=rs_tyr("tyr")%>" <%if rs_tyr("tyr")="托浦" then response.write("selected")%>><%=rs_tyr("tyr")%></option>
<%
rs_tyr.movenext
Wend
rs_tyr.close
%>					
		</select>
</td>
    <th>承运人</th>
    <td>
	<select name="cyr">
	<%
		set rs_cyr = Server.CreateObject("ADODB.Recordset")
		sql="select clid,clm,cph from (select cl.clid as a,count(cl.clid) as n from(SELECT cl.clid , yb.cyr FROM cl LEFT JOIN yb ON cl.clid = yb.cyr) group by cl.clid order by count(cl.clid) desc),cl where cl.clid=a"
		rs_cyr.open sql,conn,1,1
		while not rs_cyr.eof
	%>
		<option value="<%=rs_cyr("clid")%>"><%=rs_cyr("clm")%>(<%=rs_cyr("cph")%>)</option>
	<%
			rs_cyr.movenext()
		wend
		rs_cyr.close
	%>
	</select>
	</td>
  </tr>
  <tr>
    <th>地点</th>
    <td>
	  <select name="dd" id="dd">
        <option value=""></option>
		<%
		set rs_dd = Server.CreateObject("ADODB.Recordset")
		sql="select didian from yj group by didian"
		rs_dd.open sql,conn,1,1
		while not rs_dd.eof
		%>
        <option value="<%=rs_dd("didian")%>"><%=rs_dd("didian")%></option>
	<%
			rs_dd.movenext()
		wend
		rs_dd.close
	%>
      </select>
		&nbsp;时间
		<select id="sj" name="sj">
			<option value="0:00">0:00</option>
			<option value="1:00">1:00</option>
			<option value="2:00">2:00</option>
			<option value="3:00">3:00</option>
			<option value="4:00">4:00</option>
			<option value="5:00">5:00</option>
			<option value="6:00">6:00</option>
			<option value="7:00">7:00</option>
			<option value="8:00">8:00</option>
			<option value="9:00">9:00</option>
			<option value="10:00">10:00</option>
			<option value="11:00">11:00</option>
			<option value="12:00">12:00</option>
			<option value="13:00">13:00</option>
			<option value="14:00">14:00</option>
			<option value="15:00">15:00</option>
			<option value="16:00">16:00</option>
			<option value="17:00">17:00</option>
			<option value="18:00">18:00</option>
			<option value="19:00">19:00</option>
			<option value="20:00">20:00</option>
			<option value="21:00">21:00</option>
			<option value="22:00">22:00</option>
			<option value="23:00">23:00</option>
		</select>
	</td>
    <th>船名/航次</th>
    <td><input name="cmhc" id="cmhc" /></td>
  </tr>
  <tr>
    <th>提单号</th>
    <td><input name="tdh" id="tdh" /></td>
    <th>箱型</th>
    <td>
		<select name="xx" id="xx">
        <option value="40">40</option>
        <option value="20">20</option>
        <option value="45">45</option>
		</select>
	  </td>
  </tr>
  <tr>
    <th>箱号</th>
    <td><input name="xh" id="xh" /><span id="xh_memo"></span></td>
    <th>封号</th>
    <td><input name="fh" id="fh" /></td>
  </tr>
		<tr>
			<th colspan="4"><font size="4">成本费用</font></th>
		</tr>
  <tr>
    <th>提箱</th>
    <td>
		<select name="tixiang" id="tixiang">
        <option value=""></option>
		<%
		set rs_tx = Server.CreateObject("ADODB.Recordset")
		sql="select * from tx"
		rs_tx.open sql,conn,1,1
		while not rs_tx.eof
		%>
        <option value="<%=rs_tx("tixiang")%>"><%response.write(rs_tx("tixiang")&"("&rs_tx("tixiangjiage")&")")%></option>
	<%
			rs_tx.movenext()
		wend
		rs_tx.close
	%>
      </select>
</td>
    <th>还箱</th>
    <td>
	<select name="huanxiang" id="huanxiang">
        <option value=""></option>
		<%
		set rs_hx = Server.CreateObject("ADODB.Recordset")
		sql="select * from hx"
		rs_hx.open sql,conn,1,1
		while not rs_hx.eof
		%>
        <option value="<%=rs_hx("huanxiang")%>"><%response.write(rs_hx("huanxiang")&"("&rs_hx("huanxiangjiage")&")")%></option>
	<%
			rs_hx.movenext()
		wend
		rs_hx.close
	%>
      </select>
</td>
  </tr>
  <tr>
    <th>吊机费</th>
    <td><input name="djf" id="djf" /></td>
    <th>产值</th>
    <td><input name="chanzhi" id="chanzhi" /></td>
  </tr>
  <tr>
    <th>指导过路费</th>
    <td><input name="glf" id="glf" readonly="readonly" /></td>
    <th>实际过路费</th>
    <td><input name="ltf" id="ltf" /></td>
  </tr>
  <tr>
    <th>指导燃料费</th>
    <td><input name="rlf" id="rlf" readonly="readonly" /></td>
    <th>实际燃料费</th>
    <td><input name="sjrlf" id="sjrlf" /></td>
  </tr>
  <tr>
    <th>修理费</th>
    <td><input name="xlf" id="xlf" /></td>
    <th>提还费</th>
    <td><input name="thf" id="thf" /></td>
  </tr>
  <tr>
    <th>堆存费</th>
    <td><input name="dcf" id="dcf" /></td>
    <th>其他费</th>
    <td><input name="qtf" id="qtf" /></td>
  </tr>
  <tr>
    <th>成本备注</th>
    <td colspan="3"><input name="cbbz" id="cbbz" size="80" /></td>
  </tr>
		<tr>
			<th colspan="4"><font size="4">基本费用</font></th>
    </tr>
  <tr>
    <th>应收运费</th>
    <td><input name="yj" id="yj" /> 运价:<span id="zdyj"></span> 运价=地点&amp;箱型</td>
    <th>应付运费</th>
    <td><input name="jsj" id="jsj" /></td>
  </tr>
  <tr>
    <th>进港费</th>
    <td><input name="jgf" id="jgf" /> 进港费=提箱+还箱</td>
    <th>报账</th>
    <td><input name="baozhang" type="checkbox" id="baozhang" /></td>
  </tr>
  <tr>
    <th>垫资</th>
    <td><input name="dz" id="dz" /></td>
    <th>管理成本</th>
    <td><span id="glcbf"></span></td>
  </tr>
  <tr>
    <th>备注</th>
    <td colspan="3"><input name="bz" id="bz" size="80" /></td>
	</tr>
	<tr>
	<th colspan="4"><input type="submit" name="tj" value="添加" onClick="return confirm('确定添加货单吗？');" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" /></th>
	</tr>
</table>
</form>
<br />
<a href='javascript:history.go(-1)'> &lt;&lt; 返回上一页</a>


</body>
<%
conn.close
Set conn=nothing
%>
</html>
